package com.example.crm.controller;

import com.example.crm.entity.Chance;
import com.example.crm.entity.Customer;
import com.example.crm.service.CustomerService;
import com.example.crm.util.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("customer")
public class CustomerController {
    @Resource
    private CustomerService customerService;

//        @RequestMapping("/list")
//    public String finNameAndRegion(String name, String region, Model model){
//        List<Customer> list = customerService.finNameAndRegion(name,region);
//        model.addAttribute("customerList",list);
//        return "customer/list";
//    }

    @RequestMapping("/list")
    public String finNameAndRegion(String name, String region, Model model,Integer currPageNo){
        Integer page1 = currPageNo==null?1:currPageNo;

        Page page = new Page();
        page.setTotal(customerService.count(name,region)); // 数据总条数
        page.setCurrent(page1); // 设置偏移量

        // 存储数据
        List<Customer> all = customerService.finNameAndRegion(name, region, page.getOffset(), page.getPageSize());
        page.setList(all);

        model.addAttribute("customerPage",page);

        return "customer/list";
    }


}
